#include "MyObject.h"


MyObject::MyObject(void)
{
	mEntity = NULL;
	mSceneNode = NULL;

	mPosition = Ogre::Vector3(0.0, 300.0, 300.0);
	mRotation = Ogre::Quaternion(Ogre::Degree(180), Ogre::Vector3::UNIT_Y);

	mass = 0;

    speedVector[0] = 0.0;
    speedVector[1] = 0.0;
    speedVector[2] = 0.0;
}


MyObject::~MyObject(void)
{
	delete mEntity;
	delete mSceneNode;
	delete boundingBox;
}

Ogre::Entity* MyObject::getEntity(){
	return mEntity;
}
Ogre::SceneNode* MyObject::getSceneNode(){
	return mSceneNode;
}

void MyObject::initEntity(Ogre::Entity* ent){
	if(mEntity != NULL)	delete mEntity;
	mEntity = ent;
	mEntity->setCastShadows(true);
	boundingBox = new Ogre::AxisAlignedBox(mEntity->getBoundingBox());
	halfExtents = boundingBox->getHalfSize();
}
void MyObject::initSceneNode(Ogre::SceneNode* sN){
	if(mSceneNode != NULL) delete mSceneNode;
	mSceneNode = sN;
}


void MyObject::setPosition(){
	mSceneNode->setPosition(mPosition);
}
void MyObject::setOrientation(){
	mSceneNode->setOrientation(mRotation);
}


void MyObject::setPosition(Ogre::Vector3 pos){
	mPosition = pos;
	mSceneNode->setPosition(mPosition);
}
void MyObject::setOrientation(Ogre::Quaternion rot){
	mRotation = rot;
	mSceneNode->setOrientation(mRotation);

}


Ogre::Vector3 MyObject::getHalfExtents(){
	return halfExtents;
}

Ogre::Vector3 MyObject::getPosition(){
	return mPosition;
}
Ogre::Quaternion MyObject::getOrientation(){
	return mRotation;
}


Ogre::AxisAlignedBox* MyObject::getBoundingBox(){
	return boundingBox;
}

void MyObject::setMass(float m){
	mass = m;
}

float MyObject::getMass(){
	return mass;
}


void MyObject::setMaterial(const char what[]){
	material = Ogre::MaterialManager::getSingleton().getByName(what);
	mEntity->setMaterial(material);
}


void MyObject::move(float x, float y, float z){
	
	speedVector[0] = x;
	speedVector[1] = y;
	speedVector[2] = z;
	
}


void MyObject::run(){
	
    while(true){
		
        mPosition.x += speedVector[0];
        mPosition.y += speedVector[1];
        mPosition.z += speedVector[2];
		mSceneNode->setPosition(mPosition);

        this->msleep(16);
    }
}